<?php
namespace app\controller;

use think\Request;
use app\model\ProjectOpenSourceType;
use app\model\ProjectOpenSource;
use app\common\UtilService;

class Project extends Base
{
	/**
	 * [index 首页]
	 * @since  2022-03-25
	 * @author Dai哥
	 * @param  Request    $request [description]
	 * @return [type]              [description]
	 */
	public function index(Request $request)
	{
		# 获取分类列表
		$typeList = ProjectOpenSourceType::getProjectTypeList();

		$map = array(
			'page'  => 1,
			'limit' => 10,
		);
		$list = ProjectOpenSource::getProjectList($map);
		// dump($list->toArray());exit;
		return view('index', compact('typeList', 'list'));
	}

	/**
	 * [getAjaxProject 异步获取列表]
	 * @since  2022-03-25
	 * @author Dai哥
	 * @param  Request    $request [description]
	 * @return [type]              [description]
	 */
	public function getAjaxProject(Request $request)
	{
		try {

			$param = UtilService::getMore([
	            ['page', 1],
	            ['limit', 10],
	            ['sort', ''],
	            ['type_id', ''],
	        ]);

	        $list = ProjectOpenSource::getProjectList($param);

	        return success($list, 'ok');
	        
        } catch (\Exception $e) {

            // 这是进行异常捕获
            return error($e->getMessage());
        }
	}

	/**
	 * [article 项目详细]
	 * @since  2022-03-25
	 * @author Dai哥
	 * @param  Request    $request [description]
	 * @return [type]              [description]
	 */
	public function article(Request $request)
	{
		$param = UtilService::getMore([
            ['id', ''],
        ]);

        ProjectOpenSource::where('id', $param['id'])->inc('browse')->update();

        $info = ProjectOpenSource::getProjectOpenSourceInfo($param);
        $typeInfo = ProjectOpenSourceType::getOneTypeInfo(['id' => $info['type_id']]);

        return view('', compact('info', 'typeInfo'));
	}

	/**
	 * [special 全部开源专题列表]
	 * @since  2022-03-28
	 * @author Dai哥
	 * @param  Request    $request [description]
	 * @return [type]              [description]
	 */
	public function special(Request $request)
	{
		# 获取分类列表
		$typeList = ProjectOpenSourceType::getProjectTypeList();

		return view('special', compact('typeList'));
	}

	/**
	 * [spdetail 单个开源专题详细列表]
	 * @since  2022-03-28
	 * @author Dai哥
	 * @param  Request    $request [description]
	 * @return [type]              [description]
	 */
	public function spdetail(Request $request)
	{
		$param = UtilService::getMore([
            ['id', ''],
        ]);

		# 专题介绍
        $typeInfo = ProjectOpenSourceType::getOneTypeInfo(['id' => $param['id']]);

        $list = [];

        return view('spdetail', compact('list', 'typeInfo'));
	}
}